package modules.pathloss.model;

import tools.settings.Settings;

import datatypes.Antenna;
import tools.settings.SettingsMissingException;

/**
 *
 * @author Lynne Vandousselaere
 */
public class FreeSpace implements PathLossModel {

    // the pathloss to return
    private double[] PL = {0, 20};
    private String[] snames = {};

    @Override
    public double[] getLogDistance(Settings settings, Antenna a)
            throws SettingsMissingException {
        verifySettings(settings);
        double f = a.getFrequency();

        PL[0] = (20 * Math.log10((4 * Math.PI * Math.pow(10, 9)) / c)) +
                (20.0 * Math.log10(f));

        return PL;
    }

    @Override
    public double getPathLoss(Settings settings, Antenna a, double distance)
            throws SettingsMissingException {
        verifySettings(settings);
        
        double f = a.getFrequency();
        distance /= 1000; // to km

        return (20 * Math.log10((4 * Math.PI * Math.pow(10, 9)) / c)) +
                (20.0 * Math.log10(f)) + 20 * Math.log10(distance);
    }

    private void verifySettings(Settings settings) throws SettingsMissingException {
        //String[] snames = {};
        //if (!settings.verifySettingsExists(snames))
        //  throw SettingsMissingException.generate("PLM", "Freespace", snames);
    }

    public String[] getRequiredSettingNames() {
        return snames;
    }
}
